package fei.yuzhi.com.loveflowers.fragment.firstpagefragment.searchresult;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import fei.yuzhi.com.loveflowers.R;
import fei.yuzhi.com.loveflowers.bean.searchbean.GoodsListBean;

/**
 * Created by My on 2016/10/17.
 */
public class SearchResultListAdapter extends BaseAdapter {
    private Context context;
    private List<GoodsListBean> goodsListBeanList;
    public SearchResultListAdapter(Context context,List<GoodsListBean> goodsListBeanList){
        this.context=context;
        this.goodsListBeanList=goodsListBeanList;
    }
    @Override
    public int getCount() {
        return goodsListBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return goodsListBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_searchresult_list,null);
            holder=new ViewHolder();
            holder.imageView= (ImageView) convertView.findViewById(R.id.item_result_goodsimg);
            holder.goods_name= (TextView) convertView.findViewById(R.id.item_result_goods_name);
            holder.goods_price= (TextView) convertView.findViewById(R.id.item_result_goods_price);
            holder.goods_count= (TextView) convertView.findViewById(R.id.item_result_goods_count);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(goodsListBeanList.get(position).getGoods_image_url()).into(holder.imageView);
        holder.goods_name.setText(goodsListBeanList.get(position).getGoods_name());
        holder.goods_price.setText("￥"+goodsListBeanList.get(position).getGoods_price());
        holder.goods_count.setText("已售"+goodsListBeanList.get(position).getGoods_salenum());
        return convertView;
    }
    static class ViewHolder{
        ImageView imageView;
        TextView goods_name,goods_price,goods_count;
    }
}
